/* ==============================
   Fixed Asset Control - Responsive Global
   Mobile-First Design, Zero Overflow
   ============================== */

:root {
  --gap-1: 8px;
  --gap-2: 12px;
  --gap-3: 16px;
  --radius: 12px;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

/* ==============================
   CRITICAL: Prevent Horizontal Overflow
   ============================== */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* prevent horizontal overflow */
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ==============================
   Containers
   (Desktop: do not override .app-content — app.css / layout keeps classic shell padding)
   ============================== */
.container,
.page-container,
.content-wrapper {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 16px;
}

@media (max-width: 768px) {
  .app-content {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 16px;
  }
}

@media (max-width: 576px) {
  .container,
  .page-container,
  .content-wrapper,
  .app-content {
    padding: 12px;
  }
}

/* ==============================
   Cards / Panels
   ============================== */
.card, 
.panel, 
.box {
  border-radius: var(--radius);
  max-width: 100%;
  /* overflow: hidden removed — breaks native <select> dropdown rendering on mobile */
}

.card-body,
.card-content {
  padding: 16px;
}

@media (max-width: 576px) {
  .card-body,
  .card-content {
    padding: 12px;
  }
}

/* ==============================
   Forms: Prevent Overflow
   ============================== */
form {
  max-width: 100%;
}

input, 
select, 
textarea, 
button {
  max-width: 100%;
}

.form-row, 
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-2);
  margin-left: 0;
  margin-right: 0;
}

/* Stack Bootstrap-style columns only on narrow viewports (preserve classic multi-col desktop) */
@media (max-width: 768px) {
  .row > [class*="col-"] {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ==============================
   Form Controls: Consistent Sizing
   ============================== */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="search"],
select,
textarea,
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 0.15s ease-in-out;
}

/* Prevent iOS zoom on input focus */
@media (max-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  select,
  textarea,
  .form-control {
    font-size: 16px !important; /* iOS won't zoom if >= 16px */
  }
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ==============================
   Buttons: Wrap Properly
   ============================== */
.btn, 
button {
  white-space: normal;
  word-wrap: break-word;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Touch-friendly buttons: only narrow viewports (avoid changing desktop / mouse layout) */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  .btn,
  button,
  a[href] {
    min-height: 44px;
    min-width: 44px;
  }
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 576px) {
  .btn-group {
    flex-direction: column;
  }
  
  .btn-group .btn {
    width: 100%;
  }
}

/* ==============================
   Tables: Scroll INSIDE Wrapper Only
   CRITICAL FOR ZERO OVERFLOW
   ============================== */
.table-responsive {
  width: 100%;
  overflow: auto;           /* horizontal + vertical if needed */
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  margin-bottom: 16px;
}

/* Make table behave well in scroll container */
.table-responsive table,
.table-responsive .table {
  width: 100%;
  min-width: 720px;         /* sideways scroll for many columns */
  border-collapse: collapse;
  margin-bottom: 0;
}

.table-responsive th,
.table-responsive td {
  padding: 10px 12px;
  white-space: nowrap;      /* prevent weird wrapping */
  border: 1px solid #e5e7eb;
}

/* Sticky header for better UX */
.table-responsive thead th {
  position: sticky;
  top: 0;
  background: var(--color-table-header-bg);
  color: var(--color-text-muted);
  z-index: 2;
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
}

.table-responsive tbody tr:hover {
  background: var(--color-table-row-hover);
}

/* Mobile: reduce min-width for smaller screens */
@media (max-width: 576px) {
  .table-responsive table,
  .table-responsive .table {
    min-width: 560px;
  }
  
  .table-responsive th,
  .table-responsive td {
    padding: 8px 10px;
    font-size: 13px;
  }
}

/* ==============================
   Form Grid: 2-col desktop, 1-col mobile
   ============================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 992px) {
  .form-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 576px) {
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
  color: #374151;
}

@media (max-width: 576px) {
  .form-group label {
    font-size: 13px;
  }
}

/* ==============================
   Fix Common Overflow Sources
   ============================== */
.pre, 
pre, 
code {
  max-width: 100%;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.dropdown-menu {
  max-width: 95vw;
}

.modal-dialog {
  max-width: calc(100vw - 32px);
  margin: 16px auto;
}

@media (min-width: 768px) {
  .modal-dialog {
    max-width: 600px;
  }
}

/* ==============================
   Header / Sidebar Responsiveness
   ============================== */
.sidebar {
  max-width: 100%;
}

/* Drawer sidebar only ≤768px — same breakpoint as Travel Data batch */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    width: min(86vw, 300px);
    max-width: min(86vw, 300px);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    z-index: 12050;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.28);
  }

  .sidebar.open {
    transform: translateX(0);
    z-index: 12050;
  }

  body.sidebar-open::before {
    content: none !important;
    display: none !important;
    pointer-events: none !important;
  }

  /* Topbar stays usable when menu closed; below open sidebar */
  .topbar {
    position: sticky;
    z-index: 1200;
  }

  body.sidebar-open .topbar {
    z-index: 12030;
  }

  .content-with-sidebar,
  .app-main {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0;
  }
}

/* Touch-friendly targets on phones (WCAG ~44×44px) + faster taps */
@media (max-width: 768px) {
  .app-content .btn:not(.btn-link),
  .app-content button[type="submit"],
  .app-content .btn-group > .btn,
  .topbar .theme-btn,
  .topbar .lang-btn,
  .topbar-user-button,
  .topbar-menu-toggle,
  [data-toggle-sidebar] {
    touch-action: manipulation;
    min-height: 44px;
    box-sizing: border-box;
  }

  .topbar .lang-btn {
    min-height: 44px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .sidebar .sidebar-item,
  .sidebar .sidebar-item-parent,
  .sidebar .sidebar-submenu-item {
    min-height: 44px;
    align-items: center;
  }

  .lang-dropdown .lang-option,
  .theme-menu .theme-option,
  .user-menu .user-menu-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* Mobile menu toggle button */
.mobile-menu-toggle,
[data-toggle-sidebar] {
  display: none;
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 24px;
  color: #374151;
}

@media (max-width: 768px) {
  .mobile-menu-toggle,
  [data-toggle-sidebar] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ==============================
   Page-Level Scroll Control
   ============================== */
.page-no-scroll {
  height: 100vh;
  overflow: hidden;
}

.page-no-scroll .table-responsive {
  height: calc(100vh - 220px); /* adjust based on header/filter height */
  overflow: auto;
}

/* ==============================
   Utility Classes
   ============================== */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.w-100 {
  width: 100%;
}

.mw-100 {
  max-width: 100%;
}

/* Hide on mobile */
@media (max-width: 768px) {
  .d-none-mobile {
    display: none !important;
  }
}

/* Show only on mobile */
.d-mobile-only {
  display: none !important;
}

@media (max-width: 768px) {
  .d-mobile-only {
    display: block !important;
  }
  
  .d-mobile-flex {
    display: flex !important;
  }
}

/* ==============================
   Typography Responsiveness
   ============================== */
h1, h2, h3, h4, h5, h6 {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

@media (max-width: 576px) {
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  h4 { font-size: 1.125rem; }
  h5 { font-size: 1rem; }
  h6 { font-size: 0.875rem; }
}

/* ==============================
   Touch Optimizations (narrow screens only — keep desktop selection / scroll unchanged)
   ============================== */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  * {
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
    -webkit-overflow-scrolling: touch;
  }

  .btn,
  button,
  a {
    -webkit-user-select: none;
    user-select: none;
  }
}

/* ==============================
   Print Styles
   ============================== */
@media print {
  .sidebar,
  .mobile-menu-toggle,
  [data-toggle-sidebar],
  .btn-group,
  button {
    display: none !important;
  }
  
  .table-responsive {
    border: none;
    overflow: visible;
  }
  
  .table-responsive table {
    min-width: 100%;
  }
  
  body {
    overflow: visible;
  }
}

/* ==============================
   Safe Area for iOS Notch (phones / notched devices only)
   ============================== */
@media (max-width: 768px) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ==============================
   Loading States (Bonus)
   ============================== */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==============================
   Accessibility Improvements
   ============================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ==============================
   FILTERS GRID - RESPONSIVE
   (Wide screens: do not impose grid — page-specific / app styles keep classic layout)
   ============================== */
@media (max-width: 768px) {
  .filters-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 576px) {
  .filter-label {
    font-size: 12px;
  }
}

/* ==============================
   STATS CARDS - RESPONSIVE
   ============================== */
.stats-grid,
.kpi-grid,
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .stats-grid,
  .kpi-grid,
  .dashboard-stats {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.stat-card,
.kpi-card {
  padding: 16px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

@media (max-width: 576px) {
  .stat-card,
  .kpi-card {
    padding: 12px;
  }
}

/* ==============================
   CHARTS - RESPONSIVE
   ============================== */
.chart-container,
.chart-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.chart-container canvas {
  max-width: 100% !important;
  height: auto !important;
}

@media (max-width: 768px) {
  .chart-container {
    height: 300px !important;
  }
}

/* ==============================
   ACTION BUTTONS - RESPONSIVE
   ============================== */
.action-buttons,
.page-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

@media (max-width: 576px) {
  .action-buttons,
  .page-actions,
  .toolbar {
    flex-direction: column;
    width: 100%;
  }
  
  .action-buttons .btn,
  .page-actions .btn,
  .toolbar .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ==============================
   PAGINATION - RESPONSIVE
   ============================== */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
}

@media (max-width: 576px) {
  .pagination {
    font-size: 14px;
  }
  
  .pagination .page-link {
    padding: 6px 10px;
    min-width: 36px;
  }
}

/* ==============================
   MODAL - FULL SCREEN ON MOBILE
   ============================== */
@media (max-width: 576px) {
  .modal {
    padding: 0 !important;
  }
  
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100vh;
    display: flex;
    align-items: stretch;
  }
  
  .modal-content {
    border-radius: 0;
    border: none;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  
  .modal-body {
    flex: 1;
    overflow-y: auto;
  }
}

/* ==============================
   TABS - RESPONSIVE (horizontal scroll only when narrow)
   ============================== */
@media (max-width: 768px) {
  .nav-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    border-bottom: 2px solid #e5e7eb;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-tabs .nav-link {
    white-space: nowrap;
    font-size: 14px;
    padding: 8px 12px;
  }
}

/* ==============================
   BREADCRUMB - RESPONSIVE
   ============================== */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
}

@media (max-width: 576px) {
  .breadcrumb {
    font-size: 12px;
  }
}

/* ==============================
   DROPDOWN MENU - RESPONSIVE
   ============================== */
@media (max-width: 576px) {
  .dropdown-menu {
    position: fixed !important;
    top: auto !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 10px;
    transform: none !important;
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* ==============================
   TOPBAR - MOBILE ONLY
   (Do not override app.css / Travel topbar on desktop — classic gradient + height preserved)
   ============================== */
@media (max-width: 768px) {
  .topbar .page-title,
  .app-topbar .page-title {
    font-size: 1.125rem;
  }
}

/* Sidebar drawer: single definition @768px above (Travel-style) — no duplicate 992px rules */

/* ==============================
   WIZARD / STEPPER - RESPONSIVE
   ============================== */
.wizard-steps,
.stepper {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .wizard-steps,
  .stepper {
    flex-direction: column;
    gap: 8px;
  }
  
  .wizard-step,
  .step {
    width: 100%;
  }
}

/* ==============================
   INPUT GROUP - RESPONSIVE
   ============================== */
.input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.input-group .form-control {
  flex: 1;
  min-width: 0;
}

.input-group .btn {
  flex-shrink: 0;
}

@media (max-width: 576px) {
  .input-group {
    flex-wrap: wrap;
  }
  
  .input-group.no-wrap-mobile {
    flex-wrap: nowrap;
  }
}

/* ==============================
   ALERT / TOAST - RESPONSIVE
   ============================== */
.alert,
.toast {
  max-width: 100%;
  word-wrap: break-word;
}

@media (max-width: 576px) {
  .alert {
    font-size: 14px;
    padding: 12px;
  }
  
  .toast-container {
    left: 10px !important;
    right: 10px !important;
    top: 10px !important;
    bottom: auto !important;
    max-width: none;
  }
}

/* ==============================
   BADGE / CHIP - RESPONSIVE
   ============================== */
.badge,
.chip,
.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

@media (max-width: 576px) {
  .badge,
  .chip,
  .tag {
    font-size: 11px;
    padding: 3px 6px;
  }
}

/* ==============================
   EMPTY STATE - RESPONSIVE
   ============================== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
}

@media (max-width: 576px) {
  .empty-state {
    padding: 30px 15px;
  }
  
  .empty-state h3 {
    font-size: 1.125rem;
  }
  
  .empty-state p {
    font-size: 14px;
  }
}

/* ==============================
   FLOATING ACTION BUTTON (FAB)
   ============================== */
.fab,
.floating-action-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary, #3b82f6);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.3s ease;
}

.fab:hover,
.floating-action-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

@media (max-width: 576px) {
  .fab,
  .floating-action-btn {
    bottom: 15px;
    right: 15px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

/* ==============================
   HORIZONTAL SCROLL HINT
   ============================== */
.scroll-hint {
  position: relative;
}

.scroll-hint::after {
  content: '← ເລື່ອນຊ້າຍຂວາ →';
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  pointer-events: none;
  opacity: 0;
  animation: fadeInOut 3s ease-in-out;
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@media (min-width: 769px) {
  .scroll-hint::after {
    display: none;
  }
}

/* ==============================
   LANDSCAPE MODE WARNING
   ============================== */
@media (max-width: 768px) and (orientation: landscape) {
  .landscape-warning {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: white;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    z-index: 10000;
  }
}

/* ==============================
   Desktop / wide: larger controls & spacing (non-responsive / full-width viewing)
   ============================== */
@media (min-width: 769px) {
  :root {
    --gap-1: 10px;
    --gap-2: 14px;
    --gap-3: 18px;
  }

  .btn,
  button {
    min-height: 42px;
    padding: 10px 20px;
    font-size: 15px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
  }

  .card-body,
  .card-content {
    padding: 20px;
  }

  .container,
  .page-container,
  .content-wrapper {
    padding: 20px;
  }

  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  select,
  textarea,
  .form-control {
    padding: 12px 14px;
    font-size: 15px;
  }

  .stat-card,
  .kpi-card {
    padding: 20px;
  }
}

